package com.family.gmall.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.family.gmall.common.result.Result;
import com.family.gmall.model.product.entity.SpuInfo;
import com.family.gmall.product.service.SpuManageService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Auther: family
 * @Date: 2023/7/11 08:47
 * @Description:
 */
@Api(tags = "spu接口")
@RestController
@RequestMapping("/admin/product")
public class SpuManageController {

    @Resource
    private SpuManageService spuManageService;

    @ApiOperation("获取spu分页列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "第几页", value = "page", required = true),
            @ApiImplicitParam(name = "每页数量", value = "limit", required = true),
            @ApiImplicitParam(name = "三级分类Id", value = "category3Id", required = true)
    })
    @GetMapping("/{page}/{limit}")
    public Result getPageList(
            @PathVariable Long page,
            @PathVariable Long limit,
            SpuInfo spuInfo) {
        Page<SpuInfo> spuInfoPage = new Page<>(page, limit);
        IPage<SpuInfo> result = spuManageService.getSpuInfoPage(spuInfoPage, spuInfo);
        return Result.ok(result);
    }


    @ApiOperation("添加spu")
    @ApiImplicitParam(name = "spu对象", value = "spuInfo", required = true)
    @PostMapping("/saveSpuInfo")
    public Result saveSpuInfo(@RequestBody SpuInfo spuInfo) {
        spuManageService.saveSpuInfo(spuInfo);
        return Result.ok();
    }

    @ApiOperation("获取销售属性")
    @GetMapping("/baseSaleAttrList")
    public Result getSaleAttrList() {
        return Result.ok(spuManageService.getBaseSaleAttrList());
    }
}
